This sample demonstrates common XML API use scenarios for the Windows.Data.Xml.Dom and Windows.Data.Xml.Xsl namespaces in the Windows Runtime.
The five scenarios demonstrated in this sample are:
- Scenario1: loading an RSS template XML file asynchronously and adding a CData section. The asynchronous loading is accomplished by using the XmlDocument.loadFromFileAsync method from the Windows.Data.Xml.Dom namespace. The XmlDocument.CreateCDataSection method is used to add the CDATA section to the RSS file.
- Scenario 2: traversing a Document Object Model (DOM) tree to update the data and save it to a file. When the user presses the Mark Hot Products button, an XPath query is used to select products from an XML file, which have an attribute named "Sell10day" that exceeds the attribute named "InStore". The "Sell10Day" value represents the quantity sold in the last ten days. These products are marked "hot" by setting the "hot" attribute for the product to 1. When the user presses the Save button, the XmlDocument.saveToFileAsync method is used to save the XML file containing the products list.
- Scenario 3: using the security settings prohibitDTD and resolveExternals when loading an XML file. prohibitDTD will prevent DTD use in a XML file. A large number of DTD entity references can cause an application to become unresponsive when loading and parsing an XML file. resolveExternals determines whether external references can be resolved during parsing. For this scenario, a user chooses a combination of these two security settings, which are properties on the XmlLoadSettings class used with the XmlDocument.loadFromFileAsync method. The user presses the Load XML File button to view the resulting XML or error.
- Scenario 4: using an XPath with the XML API for the Windows Runtime to select and filter data in a DOM tree. When a user presses the
Show Anniversary Gift button, the scenario constructs an array of XPath queries used by the
XmlDocument.SelectNodes method against an XML file to determine an anniversary gift for each employee based on the year the employee started the job.
- Employees with between 1 and 4 years on the job receive a gift card.
- Employees with between 5 and 9 years on the job receive an XBOX.
- Employees with 10 or more years on the job receive a Windows Phone.
- Scenario 5: using eXtensible Stylesheet Language Transformations (XSLT) with the XML APIs to transform an XML file into an HTML webpage. The source XML and XSL are loaded during initialization of the scenario. The XSL transform is applied when the user presses the Transform button. The Source XML and Source XSL can both be modified during runtime to see different results when applying an XSL transform. The transform is applied using the XsltProcessor class from the Windows.Data.Xml.Xsl namespace.
To obtain an evaluation copy of Windows 8.1, go to Windows 8.1.
To obtain an evaluation copy of Microsoft Visual Studio 2013, go to Visual Studio 2013.
Note For Windows 8 app samples, download the Windows 8 app samples pack. The samples in the Windows 8 app samples pack will build and run only on Microsoft Visual Studio 2012.
Related topics
Related technologies
Windows.Data.Xml.Dom , Windows.Data.Xml.XslOperating system requirements
| Client | |
|---|---|
| Server |
Build the sample
- Start Visual Studio 2013 and select File > Open > Project/Solution.
- Go to the directory in which you unzipped the sample. Go to the directory named for the sample, and double-click the Microsoft Visual Studio Solution (.sln) file.
- Press F7 or use Build > Build Solution to build the sample.
Run the sample
To run this sample after building it, go to the installation folder for this sample with launch Default.html in your browser. It is located in the <install_root>\bin\Debug folder. Alternatively in Visual Studio 2013 for Windows 8.1, press F5 (run with debugging enabled) or Ctrl+F5 (run without debugging enabled). (Or select the corresponding options from the Debug menu.)
Click a scenario to run.
- Scenario 1 is executed by typing some text in the RSS Content text box and pressing the Build RSS Feed button.
- Scenario 2 is executed by clicking the Mark Hot Products button. Clicking the Save button will save the updated XML to the Libraries\Documents\HotProducts.xml file.
- Scenario 3 is executed by clicking a security setting combination and then clicking the Load XML File button.
- Scenario 4 is executed clicking the Show Anniversary Gift button.
- Scenario 5 is executed by clicking the Transform button. You can also modify the source XML and XSL to see different results.